package com.itheima;

import com.itheima.config.SpringConfig;
import com.itheima.pojo.Account;
import com.itheima.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * @author 刘全
 * @date 2021/9/12
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SpringConfig.class}) //加载配置类
//@ContextConfiguration(locations={"classpath:applicationContext.xml"})//加载配置文件
public class app {
    /*public static void main(String[] args) {
        ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfig.class);
        AccountService bean = ac.getBean(AccountService.class);
        List<Account> all = bean.findAll();
        System.out.println(all);
    }*/
    @Autowired
    private AccountService accountService;

    @Test
    public void testFindAll() {
        List<Account> list = accountService.findAll();
        System.out.println(list);
    }

    @Test
    public void testsave() {
        Account account = new Account();
        account.setId(999);
        account.setName("全");
        account.setMoney(999999.99);
        accountService.save(account);
        System.out.println(accountService.findAll());
    }

    @Test
    public void testDeleteById() {
        accountService.delete(3);
        System.out.println(accountService.findAll());
    }

    @Test
    public void testUpdate() {
        Account account = new Account();
        account.setId(1);
        account.setName("张三");
        account.setMoney(999999.99);
        accountService.update(account);
        System.out.println(accountService.findAll());
    }
}
